from flask import Flask, render_template

from utils import mysql_util

app = Flask(__name__)


@app.route('/')
def liandong():
        data1 = []
        data2 = []
        sql = 'select usertype,count(*) from user_type group by usertype'
        db = mysql_util.MysqlHelper(database='volts', user='root', passwd='123456', port=3306, host='localhost')
        data = db.all(sql)
        # print(data)
        for i in data:
                data1.append(i[0])
                data2.append(i[1])
        print("图表联动1（路由）！")
        return render_template("liandong.html", data=data, data1=data1, data2=data2)

@app.route('/test3')
def meigui():
        data1 = []
        data2 = []
        sql = 'select userid,std_top5 from user_top5 '
        db = mysql_util.MysqlHelper(database='volts', user='root', passwd='123456', port=3306, host='localhost')
        data = db.all(sql)
        # print(data)
        for i in data:
                data1.append(i[0])
                data2.append(i[1])
        print("图表联动2（路由）！")
        return render_template("meigui.html", data=data, data1=data1, data2=data2)
if __name__ == '__main__':
    app.run()
